package com.app.dao;

import com.app.pojo.Share;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface ShareDao {

    /**
     * 添加共享文件/夹
     */
    @Insert("INSERT INTO shares(userId,path,permissions,password,creatTime,timeout) VALUES (#{userId},#{path}),#{permissions}),#{password}),#{creatTime}),#{timeout})")
    int addShare(Share share);

    /**
     * 根据id获取所有共享文件/夹
     */
    @Select("SELECT * FROM shares WHERE userId = #{userId}")
    Share[] findSharesById(String userId);

    /**
     * 搜索共享文件/夹
     */
    @Select("SELECT * FROM shares WHERE path LIKE #{path}")
    Share[] searchSharesByPath(String path);

    /**
     * 查询某个共享文件/夹
     */
    @Select("SELECT * FROM shares WHERE path = #{path} AND userId = #{userId}")
    Share findShareByIdPath(String userId, String path);

    /**
     * 删除某个共享文件/夹
     */
    @Delete("DELETE FROM shares WHERE path = #{path} AND userId = #{userId}")
    int delShareByIdPath(String userId, String path);

    @Delete("DELETE FROM shares WHERE userId = #{userId}")
    int delSharesById(String userId);
}
